<%@ page import="java.io.IOException" %>
<%@ page import="priv.pfz.qatool.annotation.QAToolName" %>
<%@ page import="priv.pfz.qatool.annotation.QAToolMethod" %>
<%@ page import="priv.pfz.qatool.annotation.QAToolParam" %>
<%@ page import="priv.pfz.qatool.enums.QAToolParamType" %>
<%@ page import="priv.pfz.qatool.enums.QAToolMethodType" %>
<%@ page import="priv.pfz.qatool.QATool" %>
<%@ page import="org.apache.poi.hssf.usermodel.HSSFWorkbook" %>
<%@ page import="priv.pfz.qatool.util.TableUtil" %>
<%@ page import="java.io.File" %>
<%@ page trimDirectiveWhitespaces="true" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%!
    @QAToolName
    String name = "在线计算器";

    @QAToolMethod(descs = {"目前支持加、减、乘、除", "太简单没啥好说明的"})
    double 计算器(
            @QAToolParam(name = "操作数1") double a,
            @QAToolParam(name = "运算符", type = QAToolParamType.SELECT,
                    selectOptions = {"+", "-", "*", "/"}) String op,
            @QAToolParam(name = "操作数2") double b) {
        if ("+".equals(op)) {
            return a + b;
        } else if ("-".equals(op)) {
            return a - b;
        } else if ("*".equals(op)) {
            return a * b;
        } else {
            return a / b;
        }
    }

    @QAToolMethod(type = QAToolMethodType.TEXT)
    String param(
            @QAToolParam(name = "这是参数名", defaultValue = "这是默认值", desc = "这是描述") String aa,
            @QAToolParam(name = "单行输入框") String a,
            @QAToolParam(name = "多行文本框", type = QAToolParamType.TEXT_AREA) String b,
            @QAToolParam(name = "日期时间选择器", type = QAToolParamType.DATE_TIME_PICKER) long c,
            @QAToolParam(name = "日期选择器", type = QAToolParamType.DATE_PICKER) long d,
            @QAToolParam(name = "钩选框", type = QAToolParamType.CHECKBOX) boolean e,
            @QAToolParam(name = "单选框", type = QAToolParamType.SELECT, selectOptions = {"A", "B", "C", "D"}) String f,
            @QAToolParam(name = "上传文件", type = QAToolParamType.FILE) File g) {
        return "ok";
    }

    @QAToolMethod(type = QAToolMethodType.HTML)
    String html() {
        TableUtil tableUtil = TableUtil.create("第一列", "第二列");
        for (int i = 0; i < 5; i++) {
            tableUtil.addRow(i, i * 2);
        }
        return tableUtil.toHtml();
    }

    @QAToolMethod(type = QAToolMethodType.EXCEL)
    HSSFWorkbook excel() {
        TableUtil tableUtil = TableUtil.create("第一列", "第二列");
        for (int i = 0; i < 10; i++) {
            tableUtil.addRow(i, i * 2);
        }
        return tableUtil.toExcel();
    }

    @QAToolMethod(type = QAToolMethodType.PRINT)
    void print() throws IOException, InterruptedException {
        for (int i = 0; i < 5; i++) {
            QATool.printLine(i);
            Thread.sleep(1000);
        }
    }

%>

<%= QATool.apply(this, request, response, out) %>